<template>
  <div class="YTCC_wrap">
    <headTop :headClass="'white_header'">YTCC</headTop>
    <div class="scroll_wrap" ref="scrollBox">
      <div class="_wrap">
        <div class="yellow_box">
          <h3>{{amount}}</h3>
          <span class="amount">Current coins (YTCC)</span>
          <router-link tag="div" to="ytccTrans" class="trans_btn">Cross rotation</router-link>
        </div>
        <div class="box_shadow"></div>
        <!-- Record the head -->
        <div class="tab_title">
          <div class="title_content" :class="`active${activeNum}`">
            <span :class="{'income': activeNum!==0, 'active_style' : activeNum===0}" @click="tabActive(0)">income</span>
            <span :class="{'expenditure': activeNum!==0, 'active_style1' : activeNum===1}" @click="tabActive(1)">expenditure</span>
          </div>
          <!-- Small calendar -->
          <div class="date_wrap" @click="goSelectStart">
            <span class="date">{{showDate}}</span>
            <span class="iconfont icon-rili"></span>
          </div>
        </div>
      </div>
      <!-- Record list -->
      <ul class="detail_list" ref="scrollBoxInner">
          <li class="public_none_data" v-if="!list.length && isRequest">No data</li>
          <li class="detail_item" v-for="(item, index) in list" :key="index" v-else>
            <div class="left_box">
              <p class="remark">{{item.typeName}}</p>
              <span class="create_time">{{item.create_at}}</span>
            </div>
            <div class="right_box">
              <p class="money">{{activeNum === 0 ? `+${item.money}` : `-${item.money}`}}</p>
              <span class="phone" v-if="item.phone">{{item.phone ? HidePhone(item.phone) : item.phone}}</span>
            </div>
          </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'YTCC',
  data () {
    return {
      amount: '',
      activeNum: Number(this.$route.query.num) || 0,
      isRequest: false, // Have you requested data?
      canRequest: true, // Can you request data, request lock?
      page: 1, // Paging default data
      hasMoreData: true, // Do you have more data?
      list: []
    };
  },
  methods: {
    tabActive (num) {
      if (this.activeNum === num) {
        return false;
      } else {
        this.page = 1;
        this.isRequest = false;
        this.list = [];
        this.activeNum = num;
        this.getInfo();
      }
    },
    // calendar event
    goSelectStart () {
      this.$store.commit('configDateWrap');
    },
    // Recording interface
    getInfo () {
      this.canRequest = false;
      this.axios.get('index/accountlog/xxm', {
        params: {
          page: this.page,
          type: this.activeNum + 1,
          time: this.startTime
        }
      }).then(({data}) => {
        this.isRequest = true;
        if (data.code === 200) {
          this.canRequest = true;
          this.amount = data.data.count;
          this.page++;
          let resObj;
          resObj = data.data.list;
          if (resObj.length < 10 || !resObj.length || !resObj) {
            this.hasMoreData = false;
          } else {
            this.hasMoreData = true;
          }
          this.list = this.list.concat(resObj);
        } else {
          this.Toast(data.message);
        }
      });
    }
  },
  watch: {
    showDate () {
      this.page = 1;
      this.isRequest = false;
      this.list = [];
      this.getInfo();
    }
  },
  computed: {
    showDate () {
      if (!this.$store.state.date.selectResult[1]) {
        return 'This month';
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1]}`;
      }
    },
    startTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
      } else {
        return this.$store.state.date.selectResult.join('-');
      }
    },
    endTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 2}`;
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1] + 1}`;
      }
    }
  },
  mounted () {
    this.$refs.scrollBox.onscroll = (e) => {
      let bottomClient = this.$refs.scrollBoxInner.clientHeight - e.target.scrollTop - e.target.clientHeight;
      if (bottomClient < 50 && this.canRequest && this.hasMoreData) this.getInfo();
    };
    this.getInfo();
  }
};
</script>

<style lang="scss" scoped>
  @import '../style/public.scss';
  .YTCC_wrap{
    height: 100%;
    padding-top: 90px;
    background: #f4f5f7;
    .scroll_wrap {
      height: 100%;
      overflow-y: scroll;
      ._wrap {
        width: 100%;
        background: #fff;
        padding: 0 30px;
        padding-top: 10px;
        height: 400px;
        position: relative;
        border-bottom: 1Px solid #e6e6e6;
        margin-bottom: 20px;
        .yellow_box {
          width: 100%;
          height: 280px;
          background: linear-gradient(180deg,#ffc507,#ff9f26);
          border-radius: 15px;
          text-align: center;
          padding-top: 20px;
          h3 {
            font-size: 68px;
            color: #fff;
            font-weight: 500;
            // height: 120px;
            // line-height: 120px;
          }
          .amount {
            font-size: 26px;
            color: #222222;
            line-height: 80px;
          }
          // Cross rotation
          .trans_btn {
            width: 220px;
            height: 57px;
            border-radius: 10px;
            border: 1Px solid #fff;
            margin: 0 auto;
            font-size: 26px;
            color: #fff;
            line-height: 57px;
          }
        }
        .box_shadow:after {
            content: '';
            display: block;
            width: 70%;
            margin: 0 auto;
            box-shadow: 0px 8px 20px 10px #ffe6c4;
            // transform: translateY(-5px);
        }
        //  Record the head
        .tab_title {
          width: 100%;
          height: 78px;
          background: #fff;
          padding: 0 30px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          position: absolute;
          bottom: 0;
          left: 0;
          .title_content{
            height: 100%;
            line-height: 78px;
            font-size: 28px;
            color: #666666;
            position: relative;
            &::after{
              display: block;
              content: '';
              width: 100px;
              height: 6px;
              background: #f8a120;
              position: absolute;
              transition: left .3s;
              bottom: 0;
              border-radius: 25px;
            }
            &.active0::after{
              left: 0px;
              content: '';
            }
            &.active1::after{
              left: calc(60%);
              content: '';
            }
            .income{
              margin-right: 60px;
            }
            .active_style {
              margin-right: 60px;
              color: #222222;
            }
            .active_style1 {
              color: #222222;
            }
          }
          .date_wrap{
            font-size: 24px;
            display: flex;
            align-items: center;
            .date{
              margin-right: 17px;
              color: #666;
            }
            .icon-rili{
              font-size: 30px;
              color: #2f2f2f;
            }
          }
        }
      }
      // Record list
      .detail_list {
        background: #fff;
        padding: 0 30px;
        position: relative;
        .detail_item {
          width: 100%;
          min-height: 142px;
          display: flex;
          justify-content: space-between;
          border-bottom: 1Px solid #e6e6e6;
          .remark, .money {
            font-size: 28px;
            color: #222222;
          }
          .create_time, .phone {
            font-size: 26px;
            color: #afafaf;
          }
          .create_time {
            padding-top: 10px;
          }
          .left_box, .right_box {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            padding: 25px 0;
          }
          .left_box {
            width: 80%;
          }
          .right_box {
            text-align: right;
            .money{
              color: $color;
            }
          }
        }
        .detail_item:last-child {
          border-bottom: none;
        }
        .public_none_data {
          position: absolute;
          // left: 0;
          // right: 0;
          // top: 0;
          // bottom: 0;
          transform: translateX(-4%);
        }
      }
    }
  }
</style>
